package com.gec.yhzh.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gec.yhzh.entity.Doctor;
import com.gec.yhzh.entity.Hospital;
import com.gec.yhzh.service.IDoctorService;
import com.gec.yhzh.service.IHospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 医院 前端控制器
 * </p>
 *
 * @author jerry
 * @since 2025-03-10
 */
@RestController
@RequestMapping("/hospital")
public class HospitalController {
    @Autowired
    private IHospitalService iHospitalService;

    //JSON解析工具
    ObjectMapper objectMapper = new ObjectMapper();
    @GetMapping("/query")
    public String  queryDoctors() throws JsonProcessingException {
        Map<String, Object> result = new HashMap<>();
        List<Hospital> doctorList = iHospitalService.list();
        if (doctorList == null || doctorList.isEmpty()) {
            result.put("flag",false );
            return objectMapper.writeValueAsString(result);
        }
        result.put("flag",true );
        result.put("list",doctorList );
        return objectMapper.writeValueAsString(result);
    }
}
